using System;
using System.Windows.Forms;

using FreeFlow.Administration;

namespace FreeFlowAdministrator
{
	/// <summary>
	/// Summary description for TablesAdaptor.
	/// </summary>
	public class TablesAdaptor : Adaptor, IRefreshable
	{
    private TableCollection tables;
		public TablesAdaptor(TableCollection tables)
		{
			this.tables = tables;
		}

    public override string Text
    {
      get
      {
        return "Tables (" + tables.Count + ")";
      }
    }

    public override object Object
    {
      get
      {
        return tables;
      }
    }

    public override void AddChildren(TreeNode node)
    {
      foreach (Table table in tables)
      {
        TreeNode childNode = TreeNodeFactory.CreateTreeNode(new TableAdaptor(table));
        node.Nodes.Add(childNode);
      }
    }

    public override int ImageIndex
    {
      get
      {
        return 32;
      }
    }

    public override Control GetRenderer()
    {
      TablesControl control = new TablesControl();
      control.LoadTables(tables);
      control.RefreshRequired += new EventHandler(TriggerRefreshRequired);
      return control;
    }

    #region IRefreshable Members

    public void Refresh()
    {
      tables.Refresh();
    }

    #endregion
  }
}
